find() - model |
It searches for business objects in the data set of the model.
Syntax
Script |
iTupleIndex = modelID.find([ aParameters,] oRequest, sScope, bFindIfModified) |
Parameters
Parameter |
Description |
---|---|
aParameters |
A collection of parameters available for searching data. The collection consists of the following items:
|
oRequest |
It denotes the request object used for searching. The oRequest object overrides the aParameters specified. If oRequest object is not specified, the search is done based on the aParameters collection. |
sScope |
A string that determines the scope of the search. This parameter is optional. The possible values are:
|
bFindIfModified |
This parameter is optional. It is a boolean that specifies whether the search must be performed even when data is modified locally. The possible values are:
|
Return Value
Returns the tupleindex of the first business object in the data set that is returned by the search. If the business object is not found, then returns - '100' as the default value.
Remarks
This method applies to transactional models only. It performs a silent search, which means that it returns results without displaying the Search window.
The Find operation is not performed on the model if:
- There are no requests and parameters specified for the method.
- Records are already edited on the view and the bFindIfModified value is false.
However, if both the parameters and request are mentioned, parameters are not considered as request inputs. They are instead used for searching the business object in the response of the model data.
The scope of a Find (search) action is to find a specific object (local or global). However, when searching for a range of objects (for example, using fromEmployeeID and toEmployeeID ), the scope is always global.
Sample 1
The following example depicts the usage of parameters. In this example, find searches for the business object based on the parameters passed. If the business object is not found, a request is sent to the server and data is fetched based on these parameters. Here, the scope is default.
function find_Click(eventObject) { var aParameters = new Array(); aParameters[0] = {parameter:"fromEmployeeID", value:"20"}; aParameters[1] = {parameter:"toEmployeeID", value:"40"}; EmployeesModel.find(aParameters); }
Sample 2
The following example depicts the usage of a request.
function find_Click(eventObject) { var customRequest = findRequest.XMLDocument.cloneNode(true); // fromEmpID and toEmpID are input fields for providing search parameters. cordys.setTextcontent(cordys.selectXMLNode(customRequest,".//*[local-name()='fromEmployeeID']"),fromEmpID.getValue()); cordys.setTextcontent(cordys.selectXMLNode(customRequest,".//*[local-name()='toEmployeeID']"),toEmpID.getValue()); EmployeesModel.find(null,customRequest); } //The custom sample request is as follows <xml> <xml id="findRequest"> <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <GetEmployees xmlns="http://schemas.cordys.com/Employees"> <fromEmployeeID/> <toEmployeeID/> </GetEmployees> </SOAP:Body> </SOAP:Envelope> </xml> </xml>
Sample 3
The following example depicts how to find a business object based on a parameter. If the business object is not found locally, find sends a request to the server and searches the retrieved data.
function find_Click(eventObject) { var customRequest = findRequest.XMLDocument.cloneNode(true); // fromEmpID and toEmpID are input fields for providing search parameters. cordys.setTextcontent(cordys.selectXMLNode(customRequest,".//*[local-name()='fromEmployeeID']"),fromEmpID.getValue()); cordys.setTextcontent(cordys.selectXMLNode(customRequest,".//*[local-name()='toEmployeeID']"),toEmpID.getValue()); var aParameters = new Array(); aParameters[0] = {parameter:"EmployeeID",value:"4"}; /*Here, find first searches the business object which has EmployeeID as 4 and returns that business object's tupleIndex .Otherwise it send a request to the server and searches the retrieved data. If a business object is not found, it returns -100 as the default value.*/ EmployeesModel.find(aParameters,customRequest); }